package ace.module.account.core.impl.api.impl;

import ace.cmp.core.model.PageDto;
import ace.cmp.core.model.PageResultDto;
import ace.cmp.core.model.R;
import ace.module.account.api.IamAccountApi;
import ace.module.account.api.model.dto.IamAccountDetailDto;
import ace.module.account.api.model.dto.IamAccountDto;
import ace.module.account.api.model.input.IamAccountCommonInfoOutInput;
import ace.module.account.api.model.input.IamAccountModifyStatusInput;
import ace.module.account.api.model.input.IamAccountSearchInput;
import ace.module.account.api.model.input.IamAccountSearchOutInput;
import ace.module.account.api.model.input.IamAccountWithProfileSearchInput;
import ace.module.account.api.model.input.RegisterQuickByPhoneInput;
import ace.module.account.api.model.input.RegisterQuickByUsernameInput;
import ace.module.account.api.model.input.RegisterQuickByUsernameOutInput;
import ace.module.account.api.model.input.RegisterQuickByWxMiniAppIdAndOpenIdInput;
import ace.module.account.api.model.input.register.RegisterQuickByPhoneOutInput;
import ace.module.account.core.impl.dao.entity.IamAccount;
import ace.module.account.core.impl.manager.IamAccountManager;
import ace.module.account.core.impl.service.IamAccountService;
import ace.module.common.api.annotation.ApiLocalPriority;
import ace.module.common.api.model.input.PageInput;
import ace.module.common.core.impl.api.impl.SdkApiImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;


/**
 * 账户 api implements.
 *
 * @author Caspar
 *
 */
@ApiLocalPriority
@AllArgsConstructor
@Component
public class IamAccountApiImpl
    extends SdkApiImpl<IamAccount, Long, IamAccountDto, IamAccountManager>
    implements IamAccountApi {

  private final IamAccountService iamAccountService;

  @Override
  public R<Long> registerQuickByUsername(RegisterQuickByUsernameInput input) {
    Long accountId = this.iamAccountService.registerQuickByUsername(input);
    return R.ok(accountId);
  }

  @Override
  public R<Long> registerQuickByUsernameAndAppOutInfo(RegisterQuickByUsernameOutInput input) {
    Long accountId = this.iamAccountService.registerQuickByUsernameAndAppOutInfo(input);
    return R.ok(accountId);
  }

  @Override
  public R<Long> registerQuickByPhone(RegisterQuickByPhoneInput input) {
    Long accountId = iamAccountService.registerQuickByPhone(input);
    return R.ok(accountId);
  }

  @Override
  public R<Long> registerQuickByPhoneOutInput(RegisterQuickByPhoneOutInput input) {
    Long accountId = iamAccountService.registerQuickByPhoneOutInput(input);
    return R.ok(accountId);
  }

  @Override
  public R<Long> registerQuickByWxMiniAppIdAndOpenId(
      RegisterQuickByWxMiniAppIdAndOpenIdInput input) {
    Long accountId = iamAccountService.registerQuickByWxMiniAppIdAndOpenId(input);
    return R.ok(accountId);
  }

  @Override
  public R<PageResultDto<IamAccountDetailDto>> pageWithProfile(
      IamAccountWithProfileSearchInput input, PageDto page) {
    PageResultDto<IamAccountDetailDto> result = iamAccountService.pageWithProfile(input, page);
    return R.ok(result);
  }

  @Override
  public R<PageResultDto<IamAccountDetailDto>> searchForDetail(
      PageInput<IamAccountSearchInput> input) {
    PageResultDto<IamAccountDetailDto> result = iamAccountService.searchWithProfile(input);
    return R.ok(result);
  }

  @Override
  public R<PageResultDto<IamAccountDetailDto>> searchForDetailByOutInfo(
      PageInput<IamAccountSearchOutInput> input) {
    PageResultDto<IamAccountDetailDto> result = iamAccountService.searchWithProfileByOutInfo(input);
    return R.ok(result);
  }

  @Override
  public R<Void> modifyCommonInfo(IamAccountCommonInfoOutInput input) {
    iamAccountService.modifyCommonInfo(input);
    return R.ok();
  }

  @Override
  public R<Void> modifyStatus(IamAccountModifyStatusInput input) {
    iamAccountService.modifyStatus(input);
    return R.ok();
  }
}
